package com.adee.jdk8;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.stream.Stream;

public class Test3 {
    public static void main(String[] args) {
        long uniqueWords = 0;
        try {
            Stream<String> lines = Files.lines(Paths.get("E:/java/jdk/src/main/java/com/adee/jdk8/data.txt"), Charset.defaultCharset());
            uniqueWords = lines.flatMap(line -> Arrays.stream(line.split(" ")))
                    .distinct()
                    .count();

        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("unique word count: " + uniqueWords);
    }
}
